<?php
use yii\helpers\Url;
use yii\web\View;
use app\assets\ReportAsset;
ReportAsset::register($this);
$this->title = $this->context->pageTitle.Yii::$app->params['titleSuffix'];
$this->params['breadcrumbs'] = [
  \Yii::t('report', 'Report'),
  \Yii::t('common', 'Data')
];
$jsMsgs = $this->context->loadJsMsgs([
  'table',
  'dateRange',
  'report',
]);
$this->registerJs("VAM.setVar('LANGUAGE_JS', '".$jsMsgs."');", View::POS_HEAD);
?>
<div class="page-header">
  <h1>
    <?=\Yii::t('report', 'Report')?>
    <small></small>
    <?php
      $out = '';
      $exportUrl = Url::to(['report/export-report?strategy=all&creative=all&rang_date=']);
      $export = \Yii::t('report', 'Data Export');
      $exporting = \Yii::t('report', 'exporting');
      //if(!in_array($_SESSION['user_rank'], ['agent', 'advertiser'])) {
          $out = <<<FINE
            <div class="btn-group btn-group-sm pull-right" role="group" aria-label="...">
              <a class="btn btn-primary" href="$exportUrl" type="btn" id="report_download" data-loading-text="<i class='fa fa-spinner fa-spin'></i> ${exporting}...">
              <i class="fa fa-download"></i> 
              $export
              </a>
            </div>
FINE;
      echo $out;
     // }

    ?>
  </h1>
</div>
<div class="panel">
  <div class="panel-body">
    <div id="list-loading-wrap" class="local-loading-wrap"></div>
    <div class="panel panel-dotted">
      <div class="panel-heading">
        <h4>
          <i class="fa fa-filter"></i>
          <?=\Yii::t('common', 'Search Condition')?>
        </h4>
      </div>
      <div class="panel-body">
        <form class="form-horizontal" id="filter-frm" method="POST" action="#" role="form">
          <div class="row">
<!--              <div class="col-sm-4">
              <div class="form-group">
                <label for="filter_market" class="col-sm-4 control-label">选择市场：</label>
                <div class="col-sm-8">
                  <select class="form-control" id="filter_market" data-number="0" name="ad_network_id" >
                    <option value="0">全部</option>
                  </select>
                </div>
              </div>
            </div> -->
            <div class="col-sm-5">
              <div class="form-group">
                <label for="filter_campaign" class="col-sm-4 control-label"><?=\Yii::t('report', 'Label')?>：</label>
                <div class="col-sm-8">
                  <select class="form-control" id="filter_campaign" data-number="1" name="campaign" >
                    <option value="all"><?=\Yii::t('report', 'All')?></option>
                  </select>
                </div>
              </div>
            </div>
            <div class="col-sm-5">
              <div class="form-group">
                <label for="filter_launch" class="col-sm-4 control-label"><?=\Yii::t('report', 'Campaign')?>：</label>
                <div class="col-sm-8">
                  <select class="form-control" id="filter_launch" data-number="2" name="launch" >
                    <option value="all"><?=\Yii::t('report', 'All')?></option>
                  </select>
                </div>
              </div>
            </div>
            <div class="col-sm-5 vam-hidden">
              <div class="form-group">
                <label for="filter_strategy" class="col-sm-4 control-label"><?=\Yii::t('report', 'Solution')?>：</label>
                <div class="col-sm-8">
                  <select class="form-control" id="filter_strategy" data-number="3" name="strategy" >
                    <option value="all"><?=\Yii::t('report', 'All')?></option>
                  </select>
                </div>
              </div>
            </div>
            <?php
              $out = '';
              $Creative = \Yii::t('report', 'Creative');
              $All = \Yii::t('report', 'All');
              if(!in_array($_SESSION['user_rank'], ['agent', 'advertiser'])) {
                  $out = <<<FINE
                  <div class="col-sm-5 vam-hidden">
                    <div class="form-group">
                      <label for="filter_creative" class="col-sm-4 control-label">${Creative}：</label>
                      <div class="col-sm-8">
                        <select class="form-control" id="filter_creative" data-number="4" name="creative" >
                          <option value="all">$All</option>
                        </select>
                      </div>
                    </div>
                  </div>
FINE;
              echo $out;
              }

            ?>            
            
<!--             <div class="col-sm-5">
              <div class="form-group">
                <label for="filter_creative" class="col-sm-4 control-label"><?=\Yii::t('report', 'Creative')?>：</label>
                <div class="col-sm-8">
                  <select class="form-control" id="filter_creative" data-number="4" name="creative" >
                    <option value="all"><?=\Yii::t('report', 'All')?></option>
                  </select>
                </div>
              </div>
            </div> -->


          <!-- </div>
          <div class="row"> -->
            <div class="col-sm-5">
              <div class="form-group">
                <label for="filter_date" class="col-sm-4 control-label"> <?=\Yii::t('common', 'Select Date Range')?>：</label>
                <div class="col-sm-8">
                  <div class="range-date-group">
                  <span class="input-group-btn">
                    <button class="btn btn-default" id="range-date-btn" type="button"><i class="fa fa-calendar"></i></button>
                  </span>
                  <input type="text" class="form-control" id="range-date" name="range_date" value="" placeholder="<?=\Yii::t('common', 'Select Date Range')?>，<?=\Yii::t('common', 'format YYYY-MM-DD - YYYY-MM-DD')?>" title="<?=\Yii::t('common', 'Select Date Range')?>，<?=\Yii::t('common', 'format YYYY-MM-DD - YYYY-MM-DD')?>" readonly>
                </div>
                </div>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-sm-5">
              <div class="form-group">
                <div class="col-sm-2 col-sm-offset-4">
                  <button class="btn btn-success" type="submit" data-loading-text="<i class='fa fa-spinner fa-spin'></i> <?=\Yii::t('report', 'searching')?>..."><i class="fa fa-search"></i> <?=\Yii::t('report', 'Search')?></button>
                </div>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
    <div class="panel panel-dotted">
      <div class="panel-heading">
        <h4><i class="fa fa-pie-chart"></i> <?=\Yii::t('report', 'Data Trend')?></h4>
      </div>
      <div class="panel-body">
        <div class="row">
          <div class="col-sm-12">
            <!-- <div class="chart-filter" style="margin-bottom: 10px; overflow:hidden;">
              <div id="total-date-op" class="chart-date-op pull-right">
                <div data-toggle="buttons" class="btn-group">
                  <label class="btn btn-default btn-sm active">
                    <input type="radio" checked="" value="day" name="date-options">按日</label>
                  <label class="btn btn-default btn-sm">
                    <input type="radio" value="week" name="date-options">按周</label>
                  <label class="btn btn-default btn-sm">
                    <input type="radio" value="month" name="date-options">按月</label>
                </div>
              </div>
            </div> -->
            <div class="chart-holder" id="summary-report-data" style="height: 450px;"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="panel panel-dotted">
      <div class="panel-heading">
        <h4>
          <i class="fa fa-table"></i> 
          <?=\Yii::t('report', 'Data List')?>
          <ul class="list-inline list-unstyled pull-right">
            <!-- <li>
              <a class="data-table-refresh" href="#" title="点击刷新数据">
                <i class="fa fa-refresh"></i>
              </a>
            </li> -->
            <li>
              <a href="#">
                <i class="fa fa-chevron-up"></i>
              </a>
            </li>
          </ul>
        </h4>
      </div>
      <div class="panel-body">
        <!-- <div id="list-loading-wrap" class="local-loading-wrap"></div> -->
        <div class="table-responsive">
          <table class="table table-bordered table-condensed table-total">
            <tbody>
              <tr class="total-title">
                <td colspan="1" rowspan="2">
                  <strong><?=\Yii::t('report', 'Total')?></strong>
                </td>
                <td><?=\Yii::t('report', 'Cost')?></td>
                <!-- <td><?=\Yii::t('report', 'Requests')?></td> -->
                <!-- <td><?=\Yii::t('report', 'Bids')?></td> -->
                <!-- <td><?=\Yii::t('report', 'Shows')?></td> -->
                <td><?=\Yii::t('report', 'Clicks')?></td>
                <!-- <td><?=\Yii::t('report', 'Click Rate(%)')?></td> -->
                <!-- <td>CPM</td> -->
                <td>CPC</td>
              </tr>
              <tr class="total-data">
                <td>
                  <p class="text-success" title="1003.20"><i class="fa fa-rmb"></i> 0.00</p>
                  <p class="text-success" title="1003.20"><i class="fa fa-rmb"></i> 0.00</p>
                </td>
                <!-- <td title="0">0</td>
                <td title="0">0</td> -->
                <!-- <td title="0">0</td> -->
                <td title="0">0</td>
                <!-- <td title="0.00">0.00 %</td> -->
                <!-- <td>
                  <p class="text-success" title="0.00"><i class="fa fa-rmb"></i> 0.00</p>
                  <p class="text-success" title="0.00"><i class="fa fa-rmb"></i> 0.00</p>
                </td> -->
                <td>
                  <p class="text-success" title="0.00"><i class="fa fa-rmb"></i> 0.00</p>
                  <p class="text-success" title="0.00"><i class="fa fa-rmb"></i> 0.00</p>
                </td>
              </tr>
            </tbody>
          </table>
          <table class="table table-hover table-striped table-bordered table-condensed" id="data-table" data-tag="vm-adserver.campaign-report-list">
            <thead class="heading">
              <tr>
                <th data-resizable-column-id="date" data-search="on" data-filter="on"><?=\Yii::t('report', 'Date')?></th>
                <th data-resizable-column-id="id" data-search="on" data-filter="on"><?=\Yii::t('report', 'Campaign Name')?></th>
                <!-- <th>媒体</th> -->
                <th data-resizable-column-id="solution" data-search="on" data-filter="on"><?=\Yii::t('report', 'Solution Name')?></th>
                <th data-resizable-column-id="creative" data-search="on" data-filter="on"><?=\Yii::t('report', 'Creative Name')?></th>
                <th data-resizable-column-id="adspace" data-search="on" data-filter="on"><?=\Yii::t('report', 'Pack')?></th>
                <!-- <th data-resizable-column-id="belongChannel" data-search="on" data-filter="on"><?=\Yii::t('report', 'Belong Market')?></th> -->
                <!-- <th data-resizable-column-id="originCost" data-search="on"  data-search="on" data-filter="on"><?=\Yii::t('report', 'Origin Cost')?></th> -->
                <th data-resizable-column-id="cost" data-search="on" data-filter="on"><?=\Yii::t('report', 'Cost')?></th>
                <!-- <th data-resizable-column-id="reqCount" data-search="on" data-filter="on"><?=\Yii::t('report', 'Requests')?></th> -->
                <!-- <th data-resizable-column-id="bidCount" data-search="on" data-filter="on"><?=\Yii::t('report', 'Bids')?></th> -->
                <!-- <th data-resizable-column-id="showCount" data-search="on" data-filter="on"><?=\Yii::t('report', 'Shows')?></th> -->
                <th data-resizable-column-id="clickCount" data-search="on" data-filter="on"><?=\Yii::t('report', 'Clicks')?></th>
                <!-- <th>价格(CPM/元)</th> -->
                <!-- <th data-resizable-column-id="clickRate" data-search="on" data-filter="on"><?=\Yii::t('report', 'Click Rate(%)')?></th> -->
                <!-- <th>所属黑名单</th> -->
                <!-- <th data-resizable-column-id="cpm" data-search="on" data-filter="on">CPM</th> -->
                <th data-resizable-column-id="cpc" data-search="on" data-filter="on">CPC</th>
                <!-- <th>转化率</th>
                <th>转化金额</th> -->
              </tr>
            </thead>
            <tbody>
              <tr role="row">
                <td class="text-center dataTables_empty" colspan="8"><?=\Yii::t('site', 'No Records')?></td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
<?php
  $dataUrl = Url::to(['get-all-report-data']);
  //$dataUrl = Yii::getAlias('@web').'/response/report/reportDataList.php';
  //$dataPackInfoUrl = Yii::getAlias('@web').'/response/report/reportPackInfoDataList.php';
  $dataPackInfoUrl = Url::to(['get-app-report-data']);
  $exportDataUrl = Url::to(['export-report']);
  $campaignToLauch = $labelOnCampaign;
  $launchToStrategy = $campaignOnSolution;
  $strategyToCreative = $solutionOnCreative;
  $costFilterStatus = $costFilter;
  // $this->registerJs("VAM.setVar('MARKET_TO_CAMPAIGN','$marketToCampaign');", View::POS_HEAD);
  $filter = '';    // 需要屏蔽数据时 $dataFilter = ''， 显示数据 $dataFilter = true
  $this->registerJs("VAM.setVar('FILTER_STATUS','$filter');",View::POS_HEAD);
  $this->registerJs("VAM.setVar('CAMPAIGN_TO_LAUNCH','$campaignToLauch');", View::POS_HEAD);
  $this->registerJs("VAM.setVar('LAUNCH_TO_STRATEGY','$launchToStrategy');", View::POS_HEAD);
  $this->registerJs("VAM.setVar('STRATEGY_TO_CREATIVE','$strategyToCreative');", View::POS_HEAD);
  $this->registerJs("VAM.setVar('REPORT_DATA_LIST','$dataUrl');", View::POS_HEAD);
  $this->registerJs("VAM.setVar('REPORT_PACK_INFO_DATA_LIST','$dataPackInfoUrl');", View::POS_HEAD);
  $this->registerJs("VAM.setVar('EXPORT_REPORT_DATA','$exportDataUrl');", View::POS_HEAD);
  $this->registerJs("VAM.setVar('COST_FILTER_STATUS','$costFilterStatus');", View::POS_END); 
  
?>
<script type="text/javascript" >
  requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/site.js"], function(common) {
    requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/report/reportList.js"]);
  });
</script>
